

    // 日期时间差
    function timeDifferent(time1,time2,callback){           
    var totalSecond=Math.abs(time1.getTime()-time2.getTime())/1000;
    var totalMinute=totalSecond/60;
    var totalHour=totalMinute/60;
    var totalDay=totalHour/24;
    var dayDifferent=parseInt(totalDay);
    if(dayDifferent<10)
        dayDifferent='0'+dayDifferent;
    var hourDifferent=parseInt(totalHour%24);
    if(hourDifferent<10)
        hourDifferent='0'+hourDifferent;
    var minuteDifferent=parseInt(totalMinute%60);
    if(minuteDifferent<10)
        minuteDifferent='0'+minuteDifferent;
    var secondDifferent=parseInt(totalSecond%60);
    if(secondDifferent<10)
        secondDifferent='0'+secondDifferent;
    var res=+dayDifferent+"天"+hourDifferent+
            "小时"+minuteDifferent+"分钟"+secondDifferent+"秒";

    //利用回调函数将时间差返回到函数外部
    //callback 回调函数的形参
    //时间差有天数，小时，分钟，秒。可以利用对象的形式传递。
    var obj={
        days:dayDifferent,
        hours:hourDifferent,
        minutes:minuteDifferent,
        seconds:secondDifferent
    }
    return callback(obj);
    /*
        调用
     timeDifferent(time1,time2,function(value){
          //value 用来接收callback的对象obj
     })
     */
}



